Skip to content

[BUG] "Unable to retrieve content because the page is navigating and changing the content." when the page redirect #20483

Closed
@NiuBlibing

Description

Context:

  • Playwright Version: playwright==1.30.0
  • Operating System: linux
  • Node.js version: v16.18.0
  • Browser: Chromium
  • Extra:

Code Snippet

import asyncio

from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page(ignore_https_errors=True)
        response = await page.goto("http://103.26.11.236/")
        body_str = await page.content()
        print(body_str)
        await page.screenshot(path="/tmp/a.png",full_page=True)

asyncio.run(main())

Describe the bug
The url page will auto redirect to a new url when it finished loading, then await page.content() failed.

Traceback (most recent call last):
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/malicious_downloader/test.py", line 21, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/malicious_downloader/test.py", line 15, in main
    body_str = await page.content()
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/venv/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 9036, in content
    return mapping.from_maybe_impl(await self._impl_obj.content())
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/venv/lib/python3.10/site-packages/playwright/_impl/_page.py", line 474, in content
    return await self._main_frame.content()
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/venv/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 415, in content
    return await self._channel.send("content")
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 44, in send
    return await self._connection.wrap_api_call(
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 419, in wrap_api_call
    return await cb()
  File "/home/test/source/shanhai/maliciousDownloader/malicious_downloader/venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 79, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.Error: Unable to retrieve content because the page is navigating and changing the content.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @dgozman@NiuBlibing

      Issue actions

        [BUG] "Unable to retrieve content because the page is navigating and changing the content." when the page redirect · Issue #20483 · microsoft/playwright